home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / buttonbase / source / newbutton.e < prev    next >
Encoding:
Text File  |  1998-06-05  |  4.3 KB  |  126 lines

  1. /*
  2.    Name:      newbutton.e
  3.    About:     A subclass of the buttonbase Plugin for a text button
  4.    Version:   1.0 (23.5.98)
  5.    Author:    Copyright © 1998 Victor Ducedre (victord@netrover.com)
  6.  
  7.    A brief note:  This is an example of a subclass of buttonbase.  There are
  8.    some features that aren't fully implemented (such as setting pen colours
  9.    in the constructor, or using get() to get NB_TEXT).
  10.       It will, though, keep track of and implement key-press activation :-)
  11.  
  12. */
  13. OPT MODULE
  14. OPT PREPROCESS
  15. OPT OSVERSION=37
  16.  
  17. MODULE 'tools/EasyGUI', 'tools/textlen', 'graphics/rastport',
  18.        'intuition/intuition', 'intuition/gadgetclass',
  19.        'gadgets/buttonclass', 'plugins/buttonbase',
  20.        'tools/ctype', 'utility', 'utility/tagitem'
  21.  
  22. CONST NB_GADGET=$FF010001   -> kept private, and defined in each subclass
  23.  
  24. -> define NEWBUTTON to make EasyGUI's gadget list more readable!
  25. EXPORT CONST NEWBUTTON=PLUGIN
  26.  
  27. EXPORT ENUM NB_TEXT=$FF010010        -> [IS.]
  28.  
  29. EXPORT OBJECT newbutton OF buttonbase PRIVATE
  30.   label
  31.   key
  32.   pen1:INT
  33.   pen2:INT
  34.   pen3:INT
  35.   pen4:INT
  36. ENDOBJECT
  37.  
  38. PROC button(tags) OF newbutton
  39. DEF key, label
  40.   SUPER self.button(tags)  -> superclass checks for utility.library
  41.   self.label:=GetTagData(NB_TEXT, NIL, tags) OR GetTagData(GA_TEXT, NIL, tags)
  42.   IF label:=self.label
  43.     self.key:= IF (key:=InStr(label, '_'))<>-1 THEN tolower(label[key+1]) ELSE NIL
  44.     self.key:= IF isalpha(self.key) THEN self.key ELSE NIL
  45.   ENDIF
  46.   self.pen1:=-1
  47.   self.pen2:=-1
  48.   self.pen3:=-1
  49.   self.pen4:=-1
  50. ENDPROC
  51.  
  52. -> will resize() - uses superclass method
  53.  
  54. PROC min_size(ta,fh) OF newbutton
  55. ENDPROC textlen_key(self.label,ta,self.key)+16,fh+6
  56.  
  57. PROC render(ta,x,y,xs,ys,w) OF newbutton
  58. -> be sure to dynamically allocate your tag list with NEW;
  59. -> see buttonbase/settags() for more info
  60.   self.settags(NEW [GA_TEXT,        self.label,
  61.                     BUT_TEXTPEN,     self.pen1, BUT_FILLPEN,       self.pen2,
  62.                     BUT_FILLTEXTPEN, self.pen3, BUT_BACKGROUNDPEN, self.pen4,
  63.                     NIL])
  64.   SUPER self.render(ta,x,y,xs,ys,w)
  65. ENDPROC
  66.  
  67. -> clear_render() - uses superclass method
  68.  
  69. PROC message_test(imsg:PTR TO intuimessage,win:PTR TO window) OF newbutton
  70. IF Not(SUPER self.get(NB_DISABLED))
  71.   IF imsg.class=IDCMP_VANILLAKEY THEN RETURN (self.key=tolower(imsg.code))
  72.   IF imsg.class=IDCMP_GADGETUP THEN RETURN (imsg.iaddress=SUPER self.get(NB_GADGET))
  73. ENDIF
  74. ENDPROC FALSE
  75.  
  76. PROC message_action(class,qual,code,win:PTR TO window) OF newbutton
  77. IF class=IDCMP_VANILLAKEY
  78. -> Gadget activated by a key press.  ActivateGadget() does the GM_GOACTIVE method
  79. -> of the gadget which will either: a) for toggle/push buttons, come back right away
  80. -> with a IDCMP_GADGETUP message, or 2) for normal buttons, go active, until the
  81. -> gadget reads a RAWKEY_UP message (when you let go of the key)
  82.   ActivateGadget(self.get(NB_GADGET), win, NIL)
  83.   RETURN FALSE
  84. ELSE
  85.   SUPER self.set(NB_SELECTED, code)
  86. -> Use of SUPER here is only a time-saver; sending it to self.set() will work,
  87. -> since self.set() will eventually make this same call to the superclass
  88. ENDIF
  89. ENDPROC TRUE
  90.  
  91. PROC set(attr, val) OF newbutton
  92. DEF key
  93.   SELECT attr
  94.     CASE NB_TEXT  -> changes the text label, and the key equivalent when needed
  95.                         ->                *****CAUTION*****
  96.                         -> No adjustment is made to the size of the gadget
  97.                         -> (since I don't know how to signal EasyGUI to
  98.                         -> resize itself).  Supplying a new label that's
  99.                         -> larger than the one set in the constructor HAS
  100.                         -> NOT BEEN TESTED!
  101.       self.label:=val
  102.       self.key:= IF key:=InStr(val, '_')<>-1 THEN tolower(val[key+1]) ELSE NIL
  103.       self.key:= IF isalpha(self.key) THEN self.key ELSE NIL
  104.       SUPER self.set(NB_GADGET, [GA_TEXT,val,NIL])
  105.     DEFAULT
  106.       SUPER self.set(attr, val)
  107.   ENDSELECT
  108. ENDPROC
  109.  
  110. -> get() - uses superclass method
  111. -> since there's nothing really to get
  112.  
  113. PROC setcolour(colour, value) OF newbutton
  114. -> I don't know why I didn't put this in the set() method... (?!)
  115. -> BUT_ attribute values are defined in buttonclass.m
  116. DEF proceed=TRUE
  117. SELECT colour
  118.   CASE BUT_TEXTPEN;      self.pen1:=value
  119.   CASE BUT_FILLPEN;      self.pen2:=value
  120.   CASE BUT_FILLTEXTPEN;  self.pen3:=value
  121.   CASE BUT_BACKGROUNDPEN;self.pen4:=value
  122.   DEFAULT;               proceed:=FALSE
  123. ENDSELECT
  124. IF proceed THEN self.set(NB_GADGET, [colour, value, NIL])
  125. ENDPROC
  126.